package com.wsx.ones.gateway.common;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * @author wangshuaixin
 * @Title: com.wsx.ones.gateway.common.ConfigManager
 * @Description: TODO
 * @date 2019/07/18
 */
public abstract class ConfigManager {

    private static final Logger log = LogManager.getLogger(ConfigManager.class);


    public boolean load() {
        String file = null;
        try {
            file = this.configFilePath();

            if (null == file || file.length() == 0) {
                return this.loadBak();
            } else {
                this.decode(file);
                log.info("load " + file + " OK");
                return true;
            }
        } catch (Exception e) {
            log.error("load " + file + " failed, and try to load backup file", e);
            return this.loadBak();
        }
    }

    public abstract String configFilePath();


    public abstract void decode(String file);

    public boolean loadBak() {
        return true;
    }
}
